<?php
/**
 * Larfree Api类
 * @author blues
 */
namespace App\Http\Controllers\Admin\Common;

use App\Models\Common\CommonFileType;
use Illuminate\Http\Request;
use Larfree\Controllers\AdminApisController as Controller;
use App\Models\Common\CommonFile;
class FileController extends Controller
{
    public function __construct(CommonFile $model )
    {
        $this->model = $model;
        parent::__construct();
    }


    public function store(Request $request)
    {

        $fileType=CommonFileType::query()->where('id',$request->type)->first();
        $fileType->count=$fileType->count+1;
        $fileType->save();
        return parent::store($request); // TODO: Change the autogenerated stub
    }

    public function destroy($id, Request $request)
    {
        $file= $this->model->where('id',$id)->first();
        $fileType= CommonFileType::query()->where('id',$file->type)->first();
        if(!@$fileType){
            apiError('该类型已经被删除');
        }
        $fileType->count=$fileType->count-1;
        if($fileType->count<=0){
            $fileType->count=0;
        }
        $fileType->save();
        return parent::destroy($id, $request); // TODO: Change the autogenerated stub
    }
}